
package jermedit.gobjekte;
import javax.swing.SwingUtilities;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

/*
 * OR, XOR, AND
 */
public class DerivationNod extends PolygonObject {

    public DerivationNod(int x, int y, int id){ 
        this.x = x;
        this.y = y;
        this.name="";
        this.id = id;
        breite = 20;
        laenge = 20;

 obenmitte = new EditPoint (x, y - laenge);  
 mitterechts = new EditPoint(x + breite, y);
 mittelinks = new EditPoint (x - breite, y);
 untenmitte = new EditPoint(x, y + laenge);
        
        boundingBox = (new Rectangle (x-breite,y-laenge, breite*2, laenge*2)).getBounds();

    }

    @Override
    public void drawSub(Graphics2D g2) {
       Ellipse2D.Double kreis = new Ellipse2D.Double (x-breite, y-laenge, breite*2, laenge*2);  
       g2.draw(kreis);


       FontMetrics fm = g2.getFontMetrics();
       int strWidth = SwingUtilities.computeStringWidth(fm, name);
       g2.drawString(name, x-strWidth/2, y+fm.getAscent()/2);
    }

    @Override
    public boolean isInArea(int x, int y) {
        return (x > this.x-breite  && x < this.x+breite && y > this.y-laenge  && y < this.y+laenge);
    }

    public Shape getShape(){
        return (new Ellipse2D.Double (x-breite, y-laenge, breite*2, laenge*2));
    }
    
    public void move(int x, int y){
        super.move(x,y);
        // BoundingBox move
        boundingBox.move(x-breite,y-laenge);    

    //Verschiebe die Eckpunkte mit dem DerivationNod
     obenmitte.move(x, y - laenge);  
     mitterechts.move(x + breite, y);
     mittelinks.move(x - breite, y);
    untenmitte.move(x, y + laenge);
    }
    @Override
    public Point mitteLinks(){
        Point liMi = new Point(x-getBreite(),y);
        return liMi;
    }
        
    @Override
    public Point mitteOben(){
        Point miOben = new Point(x,y-getLaenge());
        return miOben;
    }
    
    @Override
    public Point mitteRechts(){
        Point miRechts = new Point(x+getBreite(),y);
        return miRechts;
    }
    
    @Override
    public Point mitteUnten(){
        Point miUnten = new Point(x,y+getLaenge());
        return miUnten;
    }
    
    @Override
    public int getBreite() {
        return breite;
    }

    @Override
    public void setBreite(int breite) {
        this.breite = breite;
    }

    @Override
    public int getLaenge() {
        return laenge;
    }

    @Override
    public void setLaenge(int länge) {
        this.laenge = länge;
    }    
    }
    


